import router from "../../../apis/routers";

const key = getFilePathStore(import.meta.url)

export const useHomeIndexStore = defineStore(key, {
    state: () => ({
        coreBaseNavightionStore: useCoreBaseNavightionStore(),
        coreTabbarItemsComponentStore: useCoreTabbarItemsComponentStore(),
        homeSettingCardComponentStore: useHomeSettingCardComponentStore(),
    }),
    actions: {
        async initStore() {
            await this.coreBaseNavightionStore.initStore().then(async (res) => {
                await res.setTitle('首页');
            });
            (await this.coreTabbarItemsComponentStore.initCustomFormatter()).onChange = () => {
                this.coreBaseNavightionStore.setTitle(getSomeValue(this.coreTabbarItemsComponentStore.active, 0) ? '首页' : '我的');
            };
            await this.homeSettingCardComponentStore.initStore();
        },
        async asyLoginOuted() {
            // TODO api:用户退出登录
            await getUserLogoutForUserInfo().then(() => {
                asyncRemoveCookie('userLoginTooken').then(() => {
                    router.push({ name: 'index' });
                })
            });
        }
    },
    persist: {
        key: key,
        storage: sessionStorage
    }
})